﻿using Leeder.Logger;
using Leeder.Util;
using NewAndong.Enum;
using NewAndong.Model;
using System;
using System.Collections.Generic;
using System.Diagnostics.Eventing.Reader;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using static System.Windows.Forms.VisualStyles.VisualStyleElement.StartPanel;

namespace NewAndong.Comm
{
    public class CalculationHelper
    {
        static readonly object _object = new object();

        /// <summary>
        /// 加法运算
        /// </summary>
        /// <param name="operationValue">被加数/和</param>
        /// <param name="variable">加数</param>
        public static void Addition(ref int operationValue, int variable)
        {
            lock (_object)
            {
                operationValue = operationValue + variable;
            }
        }

        /// <summary>
        /// 减法运算
        /// </summary>
        /// <param name="operationValue">被减数/差</param>
        /// <param name="variable">减数</param>
        public static  void Subtraction(ref int operationValue, int variable)
        {
            lock (_object)
            {
                operationValue = operationValue - variable;
            }
        }

        /// <summary>
        /// 乘法运算
        /// </summary>
        /// <param name="operationValue">被乘数/积</param>
        /// <param name="variable">乘数</param>
        public static  void Multiplication(ref int operationValue, int variable)
        {
            lock (_object)
            {
                operationValue = operationValue * variable;
            }
        }

        /// <summary>
        /// 除法运算
        /// </summary>
        /// <param name="operationValue">被除数/商</param>
        /// <param name="variable">除数</param>
        public static void Division(ref int operationValue, int variable)
        {
            lock (_object)
            {
                operationValue = operationValue / variable;
            }
        }

        /// <summary>
        /// 用户自定义计算
        /// </summary>
        /// <param name="operationValue">运算值</param>
        /// <param name="checkMethod">运算方法；1:大于  2:等于  3:小于</param>
        /// <param name="compareValue">比较值</param>
        /// <param name="returnValue">运算结果值</param>
        public static bool CustomOperation(ref int operationValue, int checkMethod, int compareValue, int returnValue)
        {
            lock (_object)
            {
                if (checkMethod == 1)
                {
                    if (operationValue > compareValue)
                    { operationValue = returnValue;
                        return true;
                    }
                }
                else if (checkMethod == 2)
                {
                    if (operationValue == compareValue)
                    { operationValue = returnValue;
                        return true;
                    }
                }
                else if (checkMethod == 3)
                {
                    if (operationValue < compareValue)
                    { operationValue = returnValue;
                        return true;
                    }
                }
                return false;
            }
        }




    }

}
